{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-27T06:32:30.525174Z",
     "start_time": "2025-10-27T06:32:30.523119Z"
    }
   },
   "source": "import torch",
   "outputs": [],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-27T06:32:30.539666Z",
     "start_time": "2025-10-27T06:32:30.537455Z"
    }
   },
   "cell_type": "code",
   "source": [
    "input=[3,4,5,6,7,\n",
    "       2,4,6,8,2,\n",
    "       1,6,7,8,4,\n",
    "       9,7,4,6,2,\n",
    "       3,7,4,5,1]"
   ],
   "id": "4b10571f3e708c1d",
   "outputs": [],
   "execution_count": 6
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-27T06:32:30.546953Z",
     "start_time": "2025-10-27T06:32:30.545376Z"
    }
   },
   "cell_type": "code",
   "source": "input=torch.torch.Tensor(input).view(1,1,5,5)",
   "id": "a95ef1583b1d5aa9",
   "outputs": [],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-27T06:32:30.552572Z",
     "start_time": "2025-10-27T06:32:30.550468Z"
    }
   },
   "cell_type": "code",
   "source": "conv_layer=torch.nn.Conv2d(in_channels=1,out_channels=1,kernel_size=3,padding=1,bias=False)",
   "id": "edfdbd6c07d81c47",
   "outputs": [],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-27T06:32:30.557840Z",
     "start_time": "2025-10-27T06:32:30.556042Z"
    }
   },
   "cell_type": "code",
   "source": [
    "kernel=torch.Tensor([1,2,3,4,5,6,7,8,9]).view(1,1,3,3)\n",
    "conv_layer.weight.data=kernel.data"
   ],
   "id": "b45ad4675f0937eb",
   "outputs": [],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-27T06:32:30.563902Z",
     "start_time": "2025-10-27T06:32:30.561729Z"
    }
   },
   "cell_type": "code",
   "source": [
    "output=conv_layer(input)\n",
    "print(output)"
   ],
   "id": "fb1f180354336ad0",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[[ 91., 162., 225., 216., 131.],\n",
      "          [114., 208., 296., 263., 150.],\n",
      "          [192., 259., 282., 214., 122.],\n",
      "          [194., 242., 254., 170.,  93.],\n",
      "          [ 96., 106., 111.,  69.,  35.]]]], grad_fn=<ConvolutionBackward0>)\n"
     ]
    }
   ],
   "execution_count": 10
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
